/*  Make the necessary includes and set up the variables.  */

#include <sys/types.h>
#include <sys/socket.h>
#include <stdio.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <stdlib.h>
#include <signal.h>

#define STRINGLEN 1024
void quit(int sig) {
}
int main()
{
  int sockfd;
  int len;
  struct sockaddr_in address;
  int result;
  char buff[STRINGLEN];
  struct sigaction act;
  int i;
  act.sa_handler = quit;
  sigemptyset(&act.sa_mask);
  act.sa_flags = 0;
  
  sigaction(SIGINT, &act, 0);

/*  Create a socket for the client.  */

    sockfd = socket(AF_INET, SOCK_STREAM, 0);

/*  Name the socket, as agreed with the server.  */

    address.sin_family = AF_INET;
    address.sin_addr.s_addr = inet_addr("127.0.0.1");
    address.sin_port = htons(9734);
    len = sizeof(address);

/*  Now connect our socket to the server's socket.  */

    result = connect(sockfd, (struct sockaddr *)&address, len);

    if(result == -1) {
        perror("oops: client3");
        exit(1);
    }

/*  We can now read/write via sockfd.  */

	do {
	  result = read(sockfd, buff, STRINGLEN);
	  if (result > 0) {
      printf("char from server = %s\n", buff);
      for (i = 0; i < result; i++) {
        printf("%x ", buff[i]);
      }
      printf("\n");
	  }
	}while(result > 0);
	close(sockfd);
	printf("client is done.\n");
	exit(0);
}
